﻿// 1.1.7.08. Sorting an array means to arrange its elements in an increasing (or decreasing) order.
// Write a program, which sorts an array using the algorithm "selection sort".
using System;

class SelectionSort
{
    private static void Less(int[] arr, int i, out int min, out int minIndex)
    {
        min = arr[i];
        minIndex = Array.IndexOf(arr, arr[i]);
        for (int j = i + 1; j < arr.GetLength(0); j++)
        {
            if (arr[j] < min)
            {
                min = arr[j];
                minIndex = j;
            }
        }
    }
    private static void SwitchTwoElements(int[] arr, int i, int min, int minIndex)
    {
        int temp = arr[i];
        arr[i] = min;
        arr[minIndex] = temp;
    }

    static void Main()
    {
        int[] arr = new int[10] { 5, 3, 1, 2, 4, 0, 9, 7, 6, 8 };

        for (int i = 0; i < arr.GetLength(0); i++)
        {
            int min;
            int minIndex;
            Less(arr, i, out min, out minIndex);
            SwitchTwoElements(arr, i, min, minIndex);
        }

        Console.WriteLine(string.Join(", ", arr));
    }
  
    
  
    
}